/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.activity.controller.c;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ykht.proj.activity.entity.CnActivityMall;
import com.ykht.proj.activity.service.CnActivityMallService;
import com.ykht.proj.common.core.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 活动节表
 *
 * @author proj code generator
 * @date 2020-12-25 15:21:19
 */
@RestController
@AllArgsConstructor
@RequestMapping("c/actMall" )
@Api(value = "cnactivitymall", tags = "c端活动节")
public class ActivityMallController {

    private final  CnActivityMallService cnActivityMallService;


	@ApiOperation(value = "通过id查询活动", notes = "通过id查询活动")
    @GetMapping("/{id}" )
    public R<CnActivityMall> getById(@PathVariable("id" ) Long id) {
        return R.ok(cnActivityMallService.getById(id));
    }

	@ApiOperation(value = "弹出活动", notes = "弹出活动")
	@GetMapping("/ejectAct" )
	public R<CnActivityMall> getByEjectFlag() {
		try {
			CnActivityMall cnActivityMall = cnActivityMallService.getOne(Wrappers.lambdaQuery(CnActivityMall.class)
					.eq(CnActivityMall::getEjectFlag,0)//弹出
					.eq(CnActivityMall::getDisplay,0));//上架
			if (cnActivityMall!=null){
				return R.ok(cnActivityMall);
			}else {
				return R.failed("暂无活动");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return R.failed("暂无活动");
		}
	}


}
